﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Tailor_CustomerSlip : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadOrderDetails();
        }
    }

    private void loadOrderDetails()
    {
        string sql = @"
            SELECT count(Tailor_OrderDetails.[OrderDetailsID])

              FROM [Tailor_OrderDetails]
            inner join Tailor_Product on Tailor_Product.ProductID =Tailor_OrderDetails.[ProductID]
            inner join Tailor_Order on Tailor_Order.OrderID =Tailor_OrderDetails.[OrderID]
            where Tailor_OrderDetails.[OrderID]=" + Request.QueryString["orderID"] + @"
            order by Tailor_Product.ProductName,Tailor_OrderDetails.[OrderDetailsID];
            
SELECT Tailor_Order.[OrderID]
      ,Tailor_Order.[CustomerID]
      ,Tailor_Order.[TotalAmount]
      ,Tailor_Order.[FabricDue]
      ,Tailor_Order.[DesignCharge]
      ,Tailor_Order.[OrderDate]
      ,Tailor_Order.[TrialDate]
      ,Tailor_Order.[DelivaryDate]
      ,Tailor_Order.[OtherCharges]
      ,Tailor_Order.[Discount]
      ,Tailor_Order.[PaidAmount]
      ,Tailor_Order.[DueAmount]
      ,Tailor_Order.[ExtraField10]
      ,Tailor_Order.[ExtraField1]
      ,Tailor_Order.[ExtraField2]
      ,Tailor_Order.[ExtraField3]
      ,Tailor_Order.[ExtraField4]
      ,Tailor_Order.[ExtraField5]
      ,Tailor_Order.[ExtraField6]
      ,Tailor_Order.[ExtraField7]
      ,Tailor_Order.[ExtraField8]
      ,Tailor_Order.[ExtraField9]
      ,Tailor_Order.[WorkStationID]
      ,Tailor_Order.[RowStatusID]
      ,Tailor_Order.[AddedBy]
      ,Tailor_Order.[AddedDate]
      ,Tailor_Order.[UpdatedDate]
      ,Tailor_Order.[UpdatedBy]
,Pos_Customer.CustomerName
,Pos_Customer.Mobile
  FROM [Tailor_Order]
inner join Pos_Customer on Pos_Customer.Pos_CustomerID = Tailor_Order.CustomerID
where [OrderID]=" + Request.QueryString["orderID"] + @"
";

        DataSet ds = CommonManager.SQLExec(sql);

        int itemCount = 0;
        decimal totalCharge = 0;

        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            itemCount += int.Parse(dr["Quantity"].ToString());
            totalCharge += decimal.Parse(dr["Charge"].ToString());
        }

        gvOrderDetails.DataSource = ds;
        gvOrderDetails.DataBind();

        ((Label)gvOrderDetails.FooterRow.FindControl("lblTotalCharge")).Text = totalCharge.ToString("0,0");
        ((Label)gvOrderDetails.FooterRow.FindControl("lblTotalQty")).Text = itemCount.ToString();

        DataRow dr_order = ds.Tables[1].Rows[0];
        lblOrderNo.Text = dr_order["OrderID"].ToString();
        txtOrderDate.Text = DateTime.Parse(dr_order["OrderDate"].ToString()).ToString("dd MMM yyyy");
        txtTrialDate.Text = DateTime.Parse(dr_order["TrialDate"].ToString()).ToString("dd MMM yyyy");
        txtDelivaryDate.Text = DateTime.Parse(dr_order["DelivaryDate"].ToString()).ToString("dd MMM yyyy");

        txtCustomerName.Text = dr_order["CustomerName"].ToString();
        txtCustomerPhone.Text = dr_order["Mobile"].ToString();

        txtFabricDue.Text = decimal.Parse(dr_order["FabricDue"].ToString()).ToString("0,0");
        txtDesignCharge.Text = decimal.Parse(dr_order["DesignCharge"].ToString()).ToString("0,0");
        txtDiscount.Text = decimal.Parse(dr_order["Discount"].ToString()).ToString("0,0");
        txtTotalPayable.Text = decimal.Parse(dr_order["OtherCharges"].ToString()).ToString("0,0");
        txtPaymentCash.Text = decimal.Parse(dr_order["ExtraField1"].ToString()).ToString("0,0");
        txtPaymentCardDBBL.Text = decimal.Parse(dr_order["ExtraField2"].ToString()).ToString("0,0");
        txtPaymentCardCITY.Text = decimal.Parse(dr_order["ExtraField3"].ToString()).ToString("0,0");
        txtDUE.Text = decimal.Parse(dr_order["DueAmount"].ToString()).ToString("0,0");
    }
}